/**
游戏上架
*/
<template>
  <div>
    <el-row>
      <el-col :span="4">
        <el-steps :space="200"  direction="vertical" :active="3" finish-status="success" align-center>
          <el-step title="基本信息"></el-step>
          <el-step title="属性参数"></el-step>
          <el-step title="游戏上架"></el-step>
        </el-steps>
      </el-col>

      <el-col :span="20">
        <el-form ref="form" :model="game" label-position="left" label-width="80px">
          <el-form-item label="游戏id">
            <el-input v-model="game.gameId" :disabled="editInput"></el-input>
          </el-form-item>

          <el-form-item label="游戏名称">
            <el-input v-model="game.gameName" :disabled="editInput"></el-input>
          </el-form-item>

          <el-form-item label="游戏简介">
            <el-input type="textarea" v-model="game.gameBriefIntro" :disabled="editInput"></el-input>
          </el-form-item>

          <el-form-item label="价格">
            <el-input-number v-model="game.price" :disabled="editInput"></el-input-number>
          </el-form-item>

          <el-form-item label="发布时间">
            <el-date-picker v-model="game.releaseTime" type="date" placeholder="选择日期" :disabled="editInput"></el-date-picker>
          </el-form-item>

          <el-form-item label="默认图片">
            <img :src="game.defaultImg" style="border-radius: 10px;width: 200px; " ></img>
          </el-form-item>

          <el-form-item>
            <el-button v-if="game != ''" type="info" :disabled="offshelfBtn" @click="editInput = false">修改</el-button>
            <el-button v-if="game != ''" type="success" :disabled="offshelfBtn" @click="putShelfGame">上架</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import goods from "@/api/game/goods";
export default {
  name: "offshelf",

  data() {
    return {
      gameId: '',
      game: {},
      editInput:true,
      offshelfBtn: false,
    }
  },

  created() {
    this.init()
  },

  methods: {
    init() {
      if (this.$route.query && this.$route.query.id) {
        this.gameId = this.$route.query.id
        this.getOffShelfGame()
      }else {
        //分页获取未上架游戏信息
        //返回发布游戏页面
        this.$confirm(
          `返回游戏配置参数页面`,
          "提示",
          {
            confirmButtonText: "确定",
            type: "warning"
          }
        ).then(result => {
          this.$router.push('game-gameattradd')
        })
      }

    },

    getOffShelfGame() {
      const param = {
        gameId: this.gameId,
      }
      goods.getOffShelfGameInfo(param)
      .then(result => {
        const data = result.data.list[0]
        if (data != null) {
          this.game = data
        }else {
          this.game = {}
        }
      })
    },

    //上架游戏
    putShelfGame() {
      this.game.offShelf = 1  //上架状态
      goods.updateGameShelfInfo(this.game)
      .then(result => {
        this.$message({
          type: "success",
          message: "上架完成"
        })
        this.editInput = true
        this.offshelfBtn = true
      })
    }
  }
}
</script>

<style scoped>

</style>
